﻿
namespace ZDS.Test

open System

open NUnit.Framework
open FsUnit

open ZDS
open TestUtility

[<TestFixture>]
type TestShareStack() =

    [<Test>]
    member this.Sample() =
        let s = new ZShareStack<int>(10)

        for index = 1 to 3 do
            s.Push 1 index
            s.Push 2 -index

        s.GetEnumerable 1 |> should equal [1;2;3]
        s.GetEnumerable 2 |> should equal [-1;-2;-3]

        for index = 1 to 4 do
            s.Push 1 <| index*index
        s.GetSize 1 |> should equal 7
        s.GetSize 2 |> should equal 3

        (fun() -> s.Push 1 100)
        |> getErrorCode
        |> should equal ErrorCode.Full

        // ------------ pop stack-2
        seq {
            for index = 1 to (s.GetSize 2) do
                yield s.Pop 2
        }
        |> should equal [-3;-2;-1]

        (fun() -> s.Pop 2 |> ignore)
        |> getErrorCode
        |> should equal ErrorCode.Empty

        // ------------ then stack-1 has more space
        s.Push 1 66
        s.Push 1 88
        s.Push 2 99
        
        (fun()-> s.Push 2 100)
        |> getErrorCode
        |> should equal ErrorCode.Full

        // ------------ pop from stack 1
        seq {
            for index = 1 to 4 do
                yield s.Pop 1
        }
        |> should equal [88;66;16;9]

        s.Push 2 100

        s.GetEnumerable 1 |> should equal [1;2;3;1;4]
        s.GetEnumerable 2 |> should equal [99;100]


    

